﻿using Domain.NHibernate.Mappings;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate.ByteCode.Castle;
using NHibernate.Cfg;
using NHibernate.Context;
using OS.Infrastructure.NHibernate;

namespace Domain.NHibernate
{
    public class NHInitializer : INHibernateInitializer
    {
        public Configuration GetConfiguration()
        {  
            MsSqlConfiguration persistenceConfigurer = MsSqlConfiguration
                    .MsSql2008
                    .ConnectionString(connectionStringBuilder => connectionStringBuilder.FromConnectionStringWithKey("ApplicationServices"))
                    .ProxyFactoryFactory<ProxyFactoryFactory>()
                    .CurrentSessionContext<ThreadStaticSessionContext>()
                    .DoNot.ShowSql();

            FluentConfiguration cfg = Fluently.Configure()
                    .Database(persistenceConfigurer)
                    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<UrlMap>());

            return cfg.BuildConfiguration();
        }

    }
}
